package com.bdqn.crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bdqn.crm.pojo.Product;
import com.bdqn.crm.pojo.Storage;
import com.bdqn.crm.service.StorageService;
import com.bdqn.crm.utils.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("storage")
public class StorageController {


    @Resource
    private StorageService storageService;

    @RequestMapping("list")
    public String list(HttpServletRequest request, Model model, @RequestParam(value = "prodName",required = false) String prodName, @RequestParam(value = "stkWarehouse",required = false) String stkWarehouse, @RequestParam(required = false, defaultValue = "1") int pageIndex){
        Page<Storage> page = new Page<>(pageIndex, 5);
        if (storageService.count(prodName,stkWarehouse) == 0) {     //此操作说明 数据库没有数据可展示，那么就全部清零
            page.setTotalElements(0);
            page.setContent(null);
        } else {
            page.setTotalElements(storageService.count(prodName,stkWarehouse));
            page.setContent(storageService.selectPages(prodName,stkWarehouse,(page.getNumber() - 1) * page.getPageSize(), page.getPageSize()));
        }
        model.addAttribute("prodName",prodName);
        model.addAttribute("stkWarehouse",stkWarehouse);
        model.addAttribute("storagePage", page);
        return "storage/list";
    }

}
